package com.itheima.dbservice;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.SoulQuestiontypeMapper;
import com.itheima.pojo.SoulQuestiontype;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SoulQuestiontypeApiImpl implements SoulQuestiontypeApi{
    @Autowired
    private SoulQuestiontypeMapper soulQuestiontypeMapper;

    @Override
    public List<SoulQuestiontype> getAll() {
        return soulQuestiontypeMapper.selectList(null);
    }

    @Override
    public void updateReportId(Integer id, Integer reportId) {
        LambdaQueryWrapper<SoulQuestiontype> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SoulQuestiontype::getId, id);
        SoulQuestiontype soulQuestiontype = soulQuestiontypeMapper.selectOne(lqw);
        if (ObjectUtil.isNull(soulQuestiontype)){
            return;
        }
        soulQuestiontype.setReportId(Convert.toStr(reportId));

        soulQuestiontypeMapper.updateById(soulQuestiontype);
    }

    @Override
    public void updateIsLock(int id) {
        LambdaQueryWrapper<SoulQuestiontype> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SoulQuestiontype::getId, id);
        SoulQuestiontype soulQuestiontype = soulQuestiontypeMapper.selectOne(lqw);
        if (ObjectUtil.isNull(soulQuestiontype)){
            return;
        }
        soulQuestiontype.setIsLock(0);

        soulQuestiontypeMapper.updateById(soulQuestiontype);
    }
}
